package com.neuedu.javase.collection;

import java.util.Comparator;
import java.util.TreeSet;

/***
 * 项目名称:  MyJavaSE 
 * 包：  com.neuedu.javase.collection 
 * date:   2025/11/5   9:49  
 * 描述:  
 *  @author : 张金山
 *  作者博客:   https://blog.fulfill.com.cn
 */
public class MyTreeSet {

    public static void main(String[] args) {

        TreeSet set = new TreeSet();

        set.add(Integer.valueOf(300));
        set.add(Integer.valueOf(100));
        set.add(Integer.valueOf(200));
        set.add(Integer.valueOf(400));


        for (Object o : set) {
            System.out.println(o);
        }


        //指定排序规则
        // TreeSet humanSet = new TreeSet(  );

        //比较器

        // Comparator<Human> comparator  = new Comparator<Human>() {
        //
        //     @Override
        //     public int compare(Human o1, Human o2) {
        //         return o1.getAge().compareTo(o2.getAge());
        //     }
        // };

        //简化之后的比较器
        Comparator<Human> comparator  =  (Human o1, Human o2)->    o1.getAge().compareTo(o2.getAge())  ;

        TreeSet humanSet = new TreeSet( comparator );
        humanSet.add(new Human("张三",18));
        humanSet.add(new Human("张三1",58));
        humanSet.add(new Human("张三2",38));
        humanSet.add(new Human("张三3",78));
        humanSet.add(new Human("张三4",58));




        for (Object o : humanSet) {
            System.out.println(o);
        }


        // System.out.println("FB".hashCode());  // 输出哈希值
        // System.out.println("Ea".hashCode());  // 输出相同的哈希值


    }
}
